﻿using QDChat.Domain;
using QDChat.Interface;
using System;


namespace QDChat.Service
{
   public class UserService
    {
        public static IChatUser Instance
        {
            get { return DataFactory.UserInstance; }
        }

        public static User Get(int id)
        {
            return Instance.Get(id);
        }

        public static int ImportUser(User user)
        {
            var old = Instance.GetByOpenId(user.OpenId);
            if (old != null)
            {
                old.Avatar = user.Avatar;
                old.NickName = user.NickName;
                old.CreateTime = DateTime.Now;
                return Instance.Update(old);
            }

            return Instance.Insert(user);
        }

        public static User GetByOpenId(string openId)
        {
            return Instance.GetByOpenId(openId);
        }
    }
}
